package com.a0soft.gphone.aTruffleHog.wnd;
/*
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 3, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * Copyright(C) 2011 
 *   Sam Lu <ysl.sam.lu (at) gmail.com>
 *
 */

import com.a0soft.gphone.aTruffleHog.R;
import com.a0soft.gphone.aTruffleHog.gio.util.UIUtils;
import com.a0soft.gphone.aTruffleHog.pref.Pref;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class DashboardFrg extends BaseFragment {
    
    @Override public View 
    onCreateView(LayoutInflater inflater, ViewGroup vgContainer,
                 Bundle bdSavedInstanceState) 
    {
        View vRoot = inflater.inflate(R.layout.dashboard_frg, vgContainer, false);
        
        vRoot.findViewById(R.id.device_info).setOnClickListener(new View.OnClickListener() {            
            @Override public void 
            onClick(View v)
            {
                ShowDeviceInfoWnd(getActivity(), false);
            }});
        
        vRoot.findViewById(R.id.os_stats).setOnClickListener(new View.OnClickListener() {            
            @Override public void 
            onClick(View v)
            {
                Context ctx = v.getContext();
                if (Pref.IsAgreeAgreement(ctx)) {
                    ShowStatsWnd(ctx);
                }
                else {
                    ctx.startActivity(new Intent(ctx, AgreementWnd.class));  
                }
            }});
        
        vRoot.findViewById(R.id.settings).setOnClickListener(new View.OnClickListener() {            
            @Override public void 
            onClick(View v)
            {
                startActivity(new Intent(getActivity(), PrefWnd.class));
            }});
        
        vRoot.findViewById(R.id.about).setOnClickListener(new View.OnClickListener() {            
            @Override public void 
            onClick(View v)
            {
                startActivity(new Intent(getActivity(), AboutWnd.class));
            }});
        
        return vRoot;
    }
    
    static void
    ShowStatsWnd(Context ctx)
    {
        Class<?> clsActivity;
        if (UIUtils.isHoneycombTablet(ctx)) {
            clsActivity = com.a0soft.gphone.aTruffleHog.wnd.tablet.StatsWnd.class;
        }
        else {
            clsActivity = com.a0soft.gphone.aTruffleHog.wnd.phone.StatsWnd.class;
        }
        ctx.startActivity(new Intent(ctx, clsActivity));        
    }
    
    static void
    ShowDeviceInfoWnd(Context ctx, boolean bForPreview)
    {
        Intent it;
        if (UIUtils.isHoneycombTablet(ctx)) {
            it = new Intent(ctx, com.a0soft.gphone.aTruffleHog.wnd.tablet.InfoWnd.class);
            it.putExtra(com.a0soft.gphone.aTruffleHog.wnd.tablet.InfoWnd.EXTRA_FOR_PREVIEW, bForPreview);
        }
        else {
            it = new Intent(ctx, com.a0soft.gphone.aTruffleHog.wnd.phone.InfoWnd.class);
            it.putExtra(com.a0soft.gphone.aTruffleHog.wnd.phone.InfoWnd.EXTRA_FOR_PREVIEW, bForPreview);
        }
        ctx.startActivity(it);        
    }
}
